!function () {
    "use strict";
    var $$ = Dom7;
    var myapp = new Framework7();
    /****微信js sdk初始化****/
    $$.ajax({
        url:'http://api.nldou.com/weixinapi/init_wx_jsapi',
        method:"GET",
        data: {fromUrl:window.location.href},
        dataType:'json',
        success: function (res) {
            if(res.code==1){
                //权限申请
                wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: res.data.appid, // 必填，公众号的唯一标识
                    timestamp: res.data.timestamp, // 必填，生成签名的时间戳
                    nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
                    signature: res.data.signature,// 必填，签名，见附录1
                    jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
                });
            }
        }
    });
    wx.ready(function () {
        wx.onMenuShareTimeline({
            title: '家庭时光游戏引导师招募', // 分享标题
            link: 'http://wap.nldou.com/gamer/index.html', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: 'http://wap.nldou.com/gamer/img/1.jpg', // 分享图标
            success: function () {return true;},
            cancel: function () {return true;}
        });
        wx.onMenuShareAppMessage({
            title: '家庭时光游戏引导师招募', // 分享标题
            desc: '想要加入游戏引导师的队伍么？赶紧来报名吧！', // 分享描述
            link: 'http://wap.nldou.com/gamer/index.html', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: 'http://wap.nldou.com/gamer/img/1.jpg', // 分享图标
            type: 'link', // 分享类型,music、video或link，不填默认为link
            success: function () {return true;},
            cancel: function () {return true;}
        });
        wx.onMenuShareQQ({
            title: '家庭时光游戏引导师招募', // 分享标题
            desc: '想要加入游戏引导师的队伍么？赶紧来报名吧！', // 分享描述
            link: 'http://wap.nldou.com/gamer/index.html', // 分享链接
            imgUrl: 'http://wap.nldou.com/gamer/img/1.jpg', // 分享图标
            success: function () {return true;},
            cancel: function () {return true;}
        });
        wx.onMenuShareWeibo({
            title: '家庭时光游戏引导师招募', // 分享标题
            desc: '想要加入游戏引导师的队伍么？赶紧来报名吧！', // 分享描述
            link: 'http://wap.nldou.com/gamer/index.html', // 分享链接
            imgUrl: 'http://wap.nldou.com/gamer/img/1.jpg', // 分享图标
            success: function () {return true;},
            cancel: function () {return true;}
        });
        wx.onMenuShareQZone({
            title: '家庭时光游戏引导师招募', // 分享标题
            desc: '想要加入游戏引导师的队伍么？赶紧来报名吧！', // 分享描述
            link: 'http://wap.nldou.com/gamer/index.html', // 分享链接
            imgUrl: 'http://wap.nldou.com/gamer/img/1.jpg', // 分享图标
            success: function () {return true;},
            cancel: function () {return true;}
        });
    });
    document.body.addEventListener('touchmove', function(evt) {
        if(!evt._isScroller) {
            evt.preventDefault()
        }
    });
    var loading = false;
    $$('.sub-btn').on('click',function () {
        var data=myapp.formToData('#info-form');
        var username = data.userName.replace(/\s/g,"");
        var email = data.email.replace(/\s/g,"");
        var phone = data.phone.replace(/\s/g,"");
        var wc1 = username.length;
        var wc2 = email.length;
        var wc3 = phone.length;
        var html = '';
        if (wc1 == 0||wc2 == 0||wc3 == 0) {
            html = '<div style="font-size: 30px;">请完善信息</div>';
            myapp.modal({text:html});
            setTimeout(function(){
                myapp.closeModal('.modal');
            },2000);
            return false;
        }else if(email.indexOf('@')==-1){
            html = '<div style="font-size: 30px;">请输入正确的邮箱</div>';
            myapp.modal({text:html});
            setTimeout(function(){
                myapp.closeModal('.modal');
            },2000);
            return false;
        }else if(!(/^1\d{10}$/).test(phone)){
            html = '<div style="font-size: 30px;">请输入正确的11位手机号</div>';
            myapp.modal({text:html});
            setTimeout(function(){
                myapp.closeModal('.modal');
            },2000);
            return false;
        }else{
            if (!loading){
                loading = true;
                $$.ajax({
                    method:'POST',
                    url:'http://api.nldou.com/gamer/preregister',
                    data:{userName:username,phone:phone,email:email},
                    dataType:'json',
                    success:function (res) {
                        // console.log(res);
                        if (res.code == 1){
                            $$("#info-form ul").hide();
                            var qrhtml = '<div class="qr-wrap flex-column flex-align-center flex-justify-around flex-nowrap" style="width: 100%;"><img src="img/gamer-admin-qrcode.jpg" style="width: 100%;margin-bottom: 20px;"><div style="display: -webkit-box;display: -ms-flexbox;display: -webkit-flex;display: flex;flex-direction: row;-ms-flex-direction: row;-webkit-flex-direction: row;-webkit-box-align: center;-ms-flex-align: center;-webkit-align-items: center;align-items: center;"><i class="f7-icons size-35" style="color: #1dd697;margin-right: 10px;">check</i><span class="size-25 bold">请扫描二维码入群</span></div></div>';
                            $$("#info-form").append(qrhtml);
                        }else{
                            var chtml = '<div style="font-size: 30px;">您已经完成注册,无需重复操作</div>';
                            myapp.modal({text:chtml});
                            setTimeout(function(){
                                myapp.closeModal('.modal');
                            },2000);
                        }
                        loading = false;
                    },
                    error:function(){
                        var chtml = '<div style="font-size: 30px;">系统繁忙请重试</div>';
                        myapp.modal({text:chtml});
                        setTimeout(function(){
                            myapp.closeModal('.modal');
                        },2000);
                        loading = false;
                    }
                });
            }
        }
    });
    $$('.showinfo-btn').on('click',function () {
        myapp.popup('.popup-register');
        var myswiper = myapp.swiper('.swiper-container',{
            direction:'vertical'
        });
        myswiper.on('slideChangeStart',function(e){
            if (e.realIndex == 5) $$('.next-slide-btn').addClass('hidden');
            else $$('.next-slide-btn').removeClass('hidden');
        });
    });
    var deg = 0;
    var dar;
    function da(){
        deg ++;
        if (deg > 360) deg = 0;
        $$('.music-btn').css('transform','rotate('+deg+'deg)');
        dar = requestAnimationFrame(da)

    }
    dar =requestAnimationFrame(da);
    $$('.music-btn').on('click',function () {
        if($$(this).hasClass('close')){
            $$(this).removeClass('close');
            $$('#audio')[0].play();
            dar = requestAnimationFrame(da);
        }else{
            $$(this).addClass('close');
            $$('#audio')[0].pause();
            cancelAnimationFrame(dar);
        }
    });
    function e(i)
    {
        this.canvas=i;
        this.ctx=this.canvas.getContext("2d");
        this.audio=$$("#audio")[0];
        this.imgList=[
            {link:"img/1.jpg",imgW:"750",imgH:"1206"},
            {link:"img/2.jpg",imgW:"1562",imgH:"2512",areaW:"138",areaH:"222",areaL:"1313",areaT:"544",limitMax:.1,limitMin:.09},
            {link:"img/3.jpg",imgW:"1562",imgH:"2512",areaW:"250",areaH:"402",areaL:"1063",areaT:"161",limitMax:.18,limitMin:.16},
            {link:"img/4.jpg",imgW:"1561",imgH:"2512",areaW:"60",areaH:"96",areaL:"708",areaT:"1868",limitMax:.05,limitMin:.04},
            {link:"img/5.jpg",imgW:"1562",imgH:"2512",areaW:"196",areaH:"316",areaL:"147",areaT:"160",limitMax:.14,limitMin:.13},
            {link:"img/6.jpg",imgW:"1562",imgH:"2512",areaW:"296",areaH:"471",areaL:"643",areaT:"1021",limitMax:1,limitMin:0}
        ];
        this.radio=1;
        this.index=0;
        this.fps=40;
        this.scale=.985;
        this.scaleSlow=.995;
    }
    function audioAutoPlay(id){
        var audio = document.getElementById(id),
            play = function(){
                audio.play();
                document.removeEventListener("touchstart",play, false);
            };
        audio.play();
        document.addEventListener("WeixinJSBridgeReady", function () {
            play();
        }, false);
        document.addEventListener('YixinJSBridgeReady', function() {
            play();
        }, false);
        document.addEventListener("touchstart",play, false);
    }
    e.prototype.initCanvas=function(){
        this.w=window.innerWidth;
        this.h=window.innerHeight;
        this.w>this.h&&(
            this.w=725,
                this.h=1206,
                $$("body").css({width:"725px",height:"1206px",margin:"0 auto",position:"relative",overflow:"hidden"}),
                $$("html").css({width:"100%",height:"100%"})
        );
        this.canvas.setAttribute("width",this.w);
        this.canvas.setAttribute("height",this.h)
    };
    e.prototype.showend=function(){
        $$("#start").hide();
        $$(".showinfo-btn").show();
    };
    e.prototype.init=function(){
        audioAutoPlay("audio");
        this.initCanvas();
        this.domList = $$(".collection .item");
        this.draw();
        this.touchEvent();
    };
    e.prototype.draw=function(){
        if(this.index+1!=this.imgList.length)
        {
            // console.log(this.radio);
            if(this.radio<this.imgList[this.index+1].areaW/this.imgList[this.index+1].imgW&&(this.index++,this.radio=1,!this.imgList[this.index+1])) return void this.showend();
            this.imgNext=this.imgList[this.index+1];
            this.imgCur=this.imgList[this.index];
            this.img_oversize=this.domList[this.index+1];
            this.img_minisize=this.domList[this.index];
            this.drawImgOversize(this.img_oversize,this.imgNext.imgW,this.imgNext.imgH,this.imgNext.areaW,this.imgNext.areaH,this.imgNext.areaL,this.imgNext.areaT,this.radio);
            this.drawImgMinisize(this.img_minisize,this.imgCur.imgW,this.imgCur.imgH,this.imgNext.imgW,this.imgNext.imgH,this.imgNext.areaW,this.imgNext.areaH,this.imgNext.areaL,this.imgNext.areaT,this.radio)
        }
    };
    e.prototype.touchEvent=function(){
        var i=this;
        $$("#start").on("touchstart",function(event){
            event.preventDefault();
            $$('.play-btn-top').css({top:'-45px'});
            function e(){
                var a=(new Date).getTime();
                if(i.index+1!=i.imgList.length){
                    if(a-t<1e3/i.fps)return void(i.timer=requestAnimationFrame(e));
                    t=a;
                    i.imgList[i.index+1].limitMax&&i.imgList[i.index+1].limitMin&&i.radio<i.imgList[i.index+1].limitMax&&i.radio>i.imgList[i.index+1].limitMin
                        ?i.radio=i.scaleSlow*i.radio:i.radio=i.scale*i.radio;
                    i.draw();
                    i.timer=requestAnimationFrame(e)
                }
            }
            cancelAnimationFrame(i.timer);
            var t=(new Date).getTime();
            i.timer=requestAnimationFrame(e);
        });
        $$("#start").on("touchmove",function(){});
        $$("#start").on("touchend",function(){$$('.play-btn-top').css({top:'-50px'});cancelAnimationFrame(i.timer)});
    };
    e.prototype.drawImgOversize=function(i,e,t,a,n,m,s,g){
        this.ctx.drawImage(i,m-(a/g-a)*(m/(e-a)),s-(n/g-n)*(s/(t-n)),a/g,n/g,0,0,750,1206)
    };
    e.prototype.drawImgMinisize=function(i,e,t,a,n,m,s,g,r,o){
        this.ctx.drawImage(i,0,0,e,t,(m/o-m)*(g/(a-m))*o*750/m,(s/o-s)*(r/(n-s))*o*1206/s,750*o,1206*o)
    };
    var a=new e($$("#app")[0]);//#app canvas
    a.init();
}();
